import { invoke } from "@tauri-apps/api/core";
import { writeText } from '@tauri-apps/plugin-clipboard-manager';

export const getTargetArchToStore = async (): Promise<string> => {
  return await invoke<string>("get_target_arch_to_store");
};

export const copy = async (text: string): Promise<void> => {
    console.log(text);
  await writeText(text);
};

export const generateShareLinks = async (category: string, pkgname: string) => {
  const targetArch = await getTargetArchToStore();
  const spkLink = `spk://${targetArch}/${category}/${pkgname}`;
  const shareLink = `https://spk-resolv.spark-app.store/?spk=spk://${targetArch}/${category}/${pkgname}`;
  const shareIframe = `<iframe src="https://spk-resolv.spark-app.store/?spk=${encodeURIComponent(`spk://${targetArch}/${category}/${pkgname}`)}" height="350" width="100%" border="0"></iframe>`;

  return {
    spkLink,
    shareLink,
    shareIframe
  };
};